{extend name="admin@publics/base"/}
{block name="title"}字典管理{/block}
{block name="body"}

<script>
//页面变量
_PAGE['adminDictionary'] = {
};
/*==========控制器==========*/
Ext.define('admin.dictionary.CURDViewController', {
	extend: 'Tg.tx.CURDViewController',
	alias: 'controller._adminDictionaryController',
    //新增
	_Add:function(button, e, eOpts){
		var _Me = this;
		if(!_Me._CheckAuth('add')){return false;}
		var _VM = _Me.getView().getViewModel();
		var _Auth = _VM.get('_Auth.add');
		var _Store = _VM.get('_MainStore');
		var _Pid = _VM.get('_Pid');
		var _Url = _VM.get('_Url.add')+'/p_id/'+_Pid;
		var _Ext = _VM.get('_Ext.add');
        var _Win = Ext.create(_Ext,{
            bbar: new Ext.Toolbar({height: 45,style: 'background: #5fa2dd;',items: [	
                '->',
                {
                    text:'保存',
                    handler:function(_SubBtn){
                        var _Form	= _SubBtn.up("window").down("form").getForm();
                        var _Params	= _Form.getValues();
						var _Return	= Ext.create('Tg.tx.Action').doAction({params:_Params,url:_Url,store:_Store});
                        if(_Return){
                        	_SubBtn.up("window").close();
                        }
                        
                    }
                },
                {
                    text:'取消',
                    handler:function(_CloseBtn){
                        _CloseBtn.up("window").close();
                    }
                }
            ]})
        });
		Ext.create('Tg.tx.Action').getDataToForm({form:_Win.down("form").getForm(),url:_Url})
	},
    //子节点
    _ColumnChild:function(_Grid, _Rindex, _Cindex) {
		var _Me	= this;
		var _V	= _Me.getView();
		var _VM = _V.getViewModel();
		var _Store	= _Grid.getStore()
		var _Select = _Store.getAt(_Rindex);
		var _Params	= {'p_id':_Select.get('id')};
		Ext.create('Tg.tx.Action').searchAction({params:_Params,store:_Store});
		_VM.set('_Pid',_Select.get('id'));
    },
	_GoFather:function(button, e, eOpts) {
		var _Me	= this;
		var _V	= _Me.getView();
		var _VM = _V.getViewModel();
		var _Store	= _Store =_VM.get('_MainStore');
		var _Params	= {'p_id':'abc20d7bde1df257f890e152af2e3470'};
		Ext.create('Tg.tx.Action').searchAction({params:_Params,store:_Store});
		_VM.set('_Pid','abc20d7bde1df257f890e152af2e3470');
    },
});
/*==========模型==========*/
Ext.define('admin.dictionary.CURDViewModel', {
	extend: 'Tg.tx.CURDViewModel',
	alias: 'viewmodel._adminDictionaryViewModel',
    //Data
    data:{
    	//权限
        _Auth:{
        	index	: {if condition="_CheckAuth('admin/Dictionary/index')"}true{else/}false{/if},
        	serch	: false,
        	add		: {if condition="_CheckAuth('admin/Dictionary/add')"}true{else/}false{/if},
        	edit	: {if condition="_CheckAuth('admin/Dictionary/edit')"}true{else/}false{/if},
        	del		: {if condition="_CheckAuth('admin/Dictionary/del')"}true{else/}false{/if},
        },
        _Url:{
        	index	: _PATH['site']+'/admin/dictionary/index',
        	add		: _PATH['site']+'/admin/dictionary/add',
        	edit	: _PATH['site']+'/admin/dictionary/edit',
        	del		: _PATH['site']+'/admin/dictionary/del',
        },
        //操作视图
        _Ext:{
        	index	: 'admin.dictionary.index',
        	serch	: 'admin.dictionary.serch',
        	add		: 'admin.dictionary.updata',
        	edit	: 'admin.dictionary.updata',
        	del		: 'admin.dictionary.del',
        },
		_Pk:'id',
		_Pid:'abc20d7bde1df257f890e152af2e3470',
    },
	//Formulas
	formulas:{
		_GoFather: function (get) {
			if(get('_Pid') == 'abc20d7bde1df257f890e152af2e3470'){
				return true;
			}else{
				return false;
			}
        },
	},
    //Store
	stores: {
		_MainStore: {
			sorters: [{property: 'sort',direction: 'asc'}],
			pageSize: 20,
			remoteSort: true,
			remoteFilter:true,
			proxy: {
				type: 'ajax',
				api: {read:_PATH['site']+'/admin/dictionary/index'},
				actionMethods:{read: "POST"},
				reader: {type: 'json',rootProperty: 'rows',totalProperty: 'total'}
			},
		},
	},
});
/*==========视图==========*/
//列表
Ext.define('admin.dictionary.index', {
	extend: 'Tg.tx.CURDList',
	alias: 'widget.admin_Dictionary_index',
	requires: [
		'admin.dictionary.CURDViewController',
		'admin.dictionary.CURDViewModel',
	],
	controller: '_adminDictionaryController',
	viewModel: '_adminDictionaryViewModel',
    _TbarLBefore:[
        {xtype: 'label',text: '字典管理',itemId:'_Tit',style: 'font-size:16px; padding-right:10px;margin-right: 10px;border-right: dotted 1px #ccc;'},
		{text: '返回',itemId:'_GoFather',bind:{hidden:'{_GoFather}'},handler: "_GoFather"}
    ],
    items:[
		{
			xtype:'CURDListGrid',
			bind:{store:'{_MainStore}'},
			columns:[
				{xtype:"actioncolumn",header:"子集",width: 50,iconCls:'tf tf-list',align:'center',locked: true,handler: '_ColumnChild',bind:{hidden:'{!_GoFather}'}},
        		{xtype:"actioncolumn",header:"更新",width: 50,iconCls:'tf tf-edit',align:'center',locked: true,handler: '_ColumnEdit',bind:{hidden:'{!_Auth.edit}'}},
				{xtype:"actioncolumn",header:"删除",width: 50,iconCls:'tf tf-del',align:'center',locked: true,handler: '_ColumnDel',bind:{hidden:'{!_Auth.del}'}},
				{dataIndex:'id', header :'主键', width :260, hidden:true, locked:true, sortable:true },
				
				{dataIndex:'title', header :'标题', width :180, hidden:false, locked:false, sortable:false },
				{dataIndex:'value', header :'值', width :180, hidden:false, locked:false, sortable:false },
				{dataIndex:'sort', header :'排序', width :60, hidden:false, locked:false, sortable:true },
				{dataIndex:'status', header :'状态', width :50, hidden:false, locked:false, sortable:true, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {return _Res_Val(_Dictionary,'sys_status', value);}},
				{dataIndex:'create_time', header :'创建时间', width :110, hidden:true, locked:false, sortable:true },
				{dataIndex:'update_time', header :'更新时间', width :110, hidden:true, locked:false, sortable:true },
			],
		},
	],
});

//操作 
Ext.define('admin.dictionary.updata', {
	extend: 'Tg.tx.Window',
	alias: 'widget.admin_Dictionary_updata',
	requires: [
		'admin.dictionary.CURDViewController',
		'admin.dictionary.CURDViewModel',
	],
	controller: '_adminDictionaryController',
	viewModel: '_adminDictionaryViewModel',
    title:'字典 - 操作',
    items:{
    	xtype:'CURDForm',
        items:[
			{items: [
				{xtype:'textfield', fieldLabel: '标题', name: 'title', itemId: 'title', cls: '', columnWidth: 1, height: 30, readOnly: false, emptyText:'请输入...'},
			]},
			{items: [
				{xtype:'textarea', fieldLabel: '值', name: 'value', itemId: 'value', cls: '', columnWidth: 1, height: 30, readOnly: false, preventScrollbars:true, emptyText:'请输入...'},
			]},
			{items: [
				{xtype:'numberfield', fieldLabel: '排序', name: 'sort', itemId: 'sort', cls: '', columnWidth: 0.5, height: 30, readOnly: false, minValue:'0', maxValue:'999999', allowDecimals:false, decimalSeparator:'.'},
				{xtype:'combobox', fieldLabel: '状态', name: 'status', itemId: 'status', cls: '', columnWidth: 0.5, height: 30, readOnly: false, emptyText:'请选择', editable:false, displayField:'text', valueField: 'value', store:{fields:['text','value'],data:_Dictionary['sys_status']}},
			]},
			{xtype:'hiddenfield', fieldLabel: '主键', name: 'id', itemId: 'id', cls: '', columnWidth: 1, height: 30, readOnly: false},
			{xtype:'hiddenfield', fieldLabel: '上级', name: 'p_id', itemId: 'p_id', cls: '', columnWidth: 1, height: 30, readOnly: false},
        ]
    }
});



//实例化
Ext.application({
	name: 'admin',
	extend: 'Ext.app.Application',
	autoCreateViewport: 'admin.dictionary.index'
});
</script>

{/block}
